import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart';


class FrameCallBackManager {
  static FrameCallBackManager? _instance;

  FrameCallBackManager._();

  late BuildContext context;

  static FrameCallBackManager get() {
    _instance ??= FrameCallBackManager._();
    return _instance!;
  }

  void init() {
    SchedulerBinding.instance.addPersistentFrameCallback((timeStamp) {
      _persistentFrameCallbackList.forEach((element) {
        element.call(timeStamp);
      });
    });
  }

  // 持久帧回调数组
  final List<FrameCallback> _persistentFrameCallbackList = [];

  // 添加持久帧回调
  void addPersistentFrameCallback(FrameCallback callback) {
    _persistentFrameCallbackList.add(callback);
  }

  // 删除持久帧回调
  void removePersistentFrameCallback(FrameCallback callback) {
    _persistentFrameCallbackList.remove(callback);
  }
}
